package com.soft.admin.web;

import java.io.IOException;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import com.soft.admin.dto.UserDTO;
import com.soft.admin.service.UserService;
import com.soft.support.PageParam;

@Controller
@RequestMapping(value = "/admin/user.do")
public class UserController extends BaseController {
	private UserService userService;
	
	@RequestMapping(params = "index")
	public String get(HttpServletResponse response, HttpServletRequest request, UserDTO params, 
			PageParam page) throws IOException {
		String res = this.userService.get(params, page);
		response.getWriter().print(res);
		return null;
	}
	
	@RequestMapping(params = "add")
	public String add(HttpServletResponse response, HttpServletRequest request, UserDTO params) 
			throws IOException {
		String res = this.userService.addOrEdit(params);
		response.getWriter().print(res);
		return null;
	}
	
	@RequestMapping(params = "edit")
	public String edit(HttpServletResponse response, HttpServletRequest request, UserDTO params) 
			throws IOException {
		String res = this.userService.addOrEdit(params);
		response.getWriter().print(res);
		return null;
	}
	
	@RequestMapping(params = "remove")
	public String remove(HttpServletResponse response, HttpServletRequest request, Integer id) 
			throws IOException {
		String res = this.userService.remove( id);
		response.getWriter().print(res);
		return null;
	}
	
	@RequestMapping(params = "configtorole")
	public String getRole(HttpServletResponse response, HttpServletRequest request) 
			throws IOException {
		String res = this.userService.getRole();
		response.getWriter().print(res);
		return null;
	}
	
	@RequestMapping(params = "configtouser")
	public String getRoleByUser(HttpServletResponse response, HttpServletRequest request, Integer id) 
			throws IOException {
		String res = this.userService.getRoleByUser(id);
		response.getWriter().print(res);
		return null;
	}
	
	@RequestMapping(params = "config")
	public String config(HttpServletResponse response, HttpServletRequest request, Integer id, 
			Integer roleId) throws IOException {
		String res = this.userService.config(id, roleId);
		response.getWriter().print(res);
		return null;
	}

	@Autowired
	public void setUserService(UserService userService) {
		this.userService = userService;
	}

}
